package com.niiwoo.civet.account.service.local;

import com.niiwoo.civet.account.dao.entity.PayChannel;
import com.niiwoo.civet.account.dao.entity.PayChannelBank;
import com.niiwoo.civet.account.dao.mapper.PayChannelBankMapperExt;
import com.niiwoo.civet.account.dao.mapper.PayChannelMapperExt;
import com.niiwoo.civet.account.enums.PayChannelTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 支付通道本地服务类
 * Created by wangjichao on 2017/11/13.
 */
@Service
public class PayChannelService {

    @Autowired
    private PayChannelMapperExt payChannelMapperExt;

    @Autowired
    private PayChannelBankMapperExt payChannelBankMapperExt;

    /**
     * 根据支付路由获取用户充值通道
     * @param userId
     * @param bankTypeId
     * @return
     */
    public PayChannel getUserRechargeChannelByRoute(String userId,Long bankTypeId){
        PayChannel payChannel = null;
        //首先查询是否存在有效期内的个人充值路由
        payChannel = payChannelMapperExt.selectUserRechargeChannelByRoute(userId,bankTypeId);
        if(payChannel != null){
            return payChannel;
        }
        //如果不存在个人路由根据银行查询全局理由
        return payChannelMapperExt.selectBankChannelByRoute(bankTypeId, PayChannelTypeEnum.PAYMENT);
    }


    /**
     * 获取支付通道对应银行配置信息
     * @param payChannelId
     * @param bankTypeId
     * @return
     */
    public PayChannelBank getPayChannelBank(Long payChannelId,Long bankTypeId){
        return payChannelBankMapperExt.selectPayChannelBank(payChannelId,bankTypeId);
    }

}
